//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#include <bsp.h>
#include <init.h>
#include "pic.h"

EXTERN_C DECL_CODEINIT void CDECL InitPIC()
{
    BspMaskAllIrqs(FALSE);
}

EXTERN_C irqs_t CDECL BspGetIrqs()
{
    return (irqs_t)Inl(_INTSR);
}

INLINE void EndOfInterrupt(irq_t irq)
{
    switch (irq) {
        case 8: Outl(_TCEOI1, 0); break;
        case 9: Outl(_TCEOI2, 0); break;
        case 22:Outl(_TCEOI3, 0); break;
    // BUG: Not implement
    }
}

EXTERN_C void CDECL BspMaskIrqs(irqs_t irqs, bool_t bEnable)
{
    if (bEnable)
        Outl(_INTENS, irqs);
    else
        Outl(_INTENC, irqs);
}

EXTERN_C void CDECL BspMaskAllIrqs(bool_t bEnable)
{
    Outl(_INTENC, 0xffffffff);
}

EXTERN_C void CDECL BspAcknowledgeIrq(irq_t irq)
{
    EndOfInterrupt(irq);
}
